<?php
class CommentListWidget extends CWidget
{
    public $dataProvider = null;
    
    public $controller = null;
    
    public $action = null;
    
    public $id = null;
    
    public function getCommentColumn($prefix = 'com_')
    {
        $column = '';
        
        switch($this->controller){
            case 'blog':
                $column = 'aid';
                break;
            case 'labs':
                if($this->action == 'sview'){
                    $column = 'solid';
                }elseif($this->action == 'view'){
                    $column = 'proid';
                }
                break;
            case 'work':
                $column = 'gid';
                break;
        }
        
        return $prefix.$column;
        
        
    }
    
    public function init()
    {
        
        
        
        $criteria = new CDbCriteria(array(        
            'condition'=>$this->getCommentColumn().'=:id',
			'order'=>'com_id DESC',
            'params'=>array(
                ':id'=>$this->id
            )
        ));        

  		$this->dataProvider=new CActiveDataProvider('Comment', array(
  				
  				'criteria' => $criteria
  					
  		));
        
    }
    
    
    public function run()
    {
        
        $this->init();
        
        $this->render('theme/light/commentlist', array(
            'dataProvider'=>$this->dataProvider,
            'controller'=>$this->controller
        ));
        
    }
    
    
}

?>